<?php
class ajax extends Controller
{
	function ajax()
	{
		 parent::Controller();
		 $this->load->library('string_library');
		 $this->load->model('ajax_model','ajax');
		 $this->load->helper('img_helper');
	}
  
	function index()
	{
		$data['title'] = '';
		$config['base_url'] = base_url().'ajax/index/'.$this->uri->segment(3);  
		$data['total'] = $this->ajax->get_total_detail();
		$config['total_rows']   =  $data['total'];
		$config['per_page']  	=  '10';
		$config['uri_segment'] 	= 4;   
		$this->pagination->initialize($config);   
		$data['list'] =   $this->ajax->getAllDetail($config['per_page'],(int)$this->uri->segment('4'));
		$data['pagination']    = $this->pagination->create_links();            
		$this->_templates['page'] = 'ajax/detail_list';
		$this->site_library->load($this->_templates['page'],$data,'basic');
	}
	
	function orderlast()
	{
		 $data['list'] = $this->ajax->get_last_order();
		 $this->load->view('ajax/orderlast',$data);
	}    
	
	function transfer_notice_last()
	{
		 $list = $this->ajax->get_transfer_notice_last();
		 $data['list'] = '
			<table class="admindata">
				 <thead>
					  <th>Mã ĐH</th>
					  <th>Tài khoản</th>
					  <th>Xem</th>
				 </thead>    
						
		 ';
		 $k=1;
		 foreach($list as $rs):
		 $data['list'] .='
			<tr class="row'.$k.'">
				 <td><a href="'.site_url('chonmua/chitietdonhang/'.$rs->CartID).'">'.$rs->CartID.'</a></td>
				 <td>'.$rs->LoginName.'</td>
				 <td><a href="'.site_url('chonmua/notice_detail/'.$rs->TransferID).'">Xem</td>
			</tr>
		 ';
		 $k=1-$k;
		 endforeach;
		$data['list'] .='</table> '; 
		 echo json_encode($data);
		 
	}
  
	function thongke()
	{
		 $this->load->view('ajax/thongke');
	}
	
	function publish()
	{
		 $status = $this->input->post('status');
		 $id = $this->input->post('id');
		 $field = $this->input->post('field');
		 $table = $this->input->post('table');
		 if($status==0){
			  $pub = 1;
		 }else{
			  $pub = 0;
		 }
		 $this->db->set('bl_active',$pub);
		 $this->db->where($field,$id);
		 $this->db->update($table);
		 echo icon_active("'$table'","'$field'",$id,$pub);
	}
  
	function getalias()
	{
		 $name = $this->input->post('name');
		 echo strtolower($this->string_library->stringchange($name));
	}
	
	function upload()
	{
		$dir = '../khuyenmai/uploads/images/';
		$size=$_FILES['imagesid']['size'];
		if($size>204857600)
		{
			echo "file_biger";
			unlink($_FILES['imagesid']['tmp_name']);
			//exit;
		}            
		
		$filename = stripslashes($_FILES['imagesid']['name']);
		$path_info = pathinfo($filename); 
		$extension = strtolower($path_info['extension']);
	
		if($extension =='jpeg')
		{
			 $extension = 'jpg';
		}
		$name = time().'.'.$extension;
		$filename = $dir.$name;
		if (move_uploaded_file($_FILES['imagesid']['tmp_name'], $filename)) 
		{
			 echo $name;
		}
		else 
		{
			 echo 'error';
		}
	}
  
  // load thuoc tinh san pham
  function loadformtype()
  {
	  $filename = $this->uri->segment(3);
	  $proid = $this->uri->segment(4);
	  if(empty($proid))
			//$data = $this->default_thuoctinh_sanpham() ;
			$data = $this->ajax->thuoctinh_default() ;
	  else
			$data = $this->ajax->thuoctinh_sanpham($proid) ;
	  
	  
	  $this->load->view('product/kind/'.$filename, $data);
  }
  
  /*function default_thuoctinh_sanpham()
  {
	  $data = array(
		"baohanh" => '',
		"congsuat" => '',
		"xuatxu" => '',
		"dungluong" => '',
		"kichthuoc" => '',
		"trongluong" => '',
		"dungluong" => '',
		"dungtich" => '',
		"chatlieu" => '',
		"giuam" => '',
		"ProID" => ''
	  ) ;
	  return $data ;
  }*/
}
?>
